<template>
  <!-- 110kV站前变 -->
  <div class="station-front borderStyle">
    <div class="station-front-title blueTitleStyle">{{stationName}}</div>
    <div class="station-front-content">
      <div
        v-for="(item, index) of deviceGroup"
        :key="index"
        class="control-group betweenbox"
        :class="{'statuson':item.status === '1','statusoff':item.status === '0'}"
        @click="handelClick(item)"
      >
        <div class="content-box" :class="{bgc:item.mystate}">
          <div class="door centerbox">
            <div
              :class="{'dooron':item.status === '1','dooroff':item.status === '0'}"
            ></div>
          </div>
          <div class="right">
            <div class="name ">{{item.name}}</div>
            <div  class="switch" :class="{on:item.status == '1'}" @click="switchFlagBtnOff(item)">
              <div
                class="switch-com centerbox"
                :class="{'btnon':item.status === '1','btnoff':item.status === '0'}"
              >{{item.status==='0'?'OFF':'ON'}}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import { LocksAPIModule } from "@/store/modules/locks";
import { log } from "three";
import { AuxiliaryMonitorModule } from "@/store/modules/AuxiliaryMonitor";

@Component
export default class StationFront extends Vue {
  switchFlag: boolean = false;
  deviceGroup: any = [];

  get stationName() {
    return this.$route.query.name || "";
  }
  setTime=setInterval(()=>{
      this.fetch()
    },10000)
  mounted() {
    this.fetch();
    this.setTime
  }
  beforeDestroy(){
clearInterval(this.setTime)
this.setTime=null
  }
  fetch() {
    var params = {
      stationId: this.$route.query.code,
    };
    (this as any).$services
      .getAccessList({ data: params })
      .then((result: any) => {
        if (result.data) {
          console.log(result);
          result.data.map((v) => {
            v.mystate = false;
          });
          this.deviceGroup = result.data;
        }
      })
      .catch((err: object) => {
        console.log(err);
      });
  }
  //   按钮开关
  switchFlagBtnOff(item: any) {
    console.log(item);
    if (item.status==1) {
      this.$message({
          type: "warning",
          message: "不能关",
        });
        return;
    }
    var params = {
      action: 1,
      doorNo: item.znwgbs,
      name: item.wgmc,
      sn: item.wgxlm,
    };
    (this as any).$services
      .changeBtn({
        data: params,
        method: "get",
      })
      .then((res: any) => {
        // console.log(res.data);
        if (res.code == 200) {
          if (item.status === "1") {
            item.status = "0";
          } else {
            item.status = "1";
          }
          this.$message({
            type: "success",
            message: `${res.message}`,
          });
        } else {
          this.$message({
            type: "warning",
            message: `${res.message}`,
          });
        }
      })
      .catch((err: object) => {
        this.$message({
          type: "warning",
          message: `操作失败！`,
        });
        console.log(err);
      });
  }
  handelClick(item) {
    this.deviceGroup.map((v) => {
      v.mystate = false;
    });
    item.mystate = true;
    this.$emit("handelClick", item.point_id);
  }
}
</script>

<style lang="scss" scoped>
.station-front {
  width: calc(100% - 0.2rem);
  height: calc(100% - 0.4rem);
  margin: 0.2rem 0.2rem 0.2rem 0;
  &-title {
    width: 100%;
    height: 0.26rem;
  }
  &-content {
    width: calc(100% - 0.3rem);
    height: calc(100% - 0.26rem);

    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    align-items: center;
    margin-left: 0.3rem;
    overflow-y: auto;
    .control-group {
      cursor: pointer;
      width: 2.65rem;
      height: 1.77rem;
      position: relative;
      margin: 0.1rem;
      box-sizing: border-box;
      .content-box {
        width: 100%;
        height: 100%;
      }
      > div {
        font-size: 0.2rem;
      }
      .door {
        width: 1.5rem;
        height: 100%;
        > div {
          width: 0.8rem;
          height: 1rem;
        }
      }
      .name {
        position: absolute;
        top: 0.4rem;
        left: 1.5rem;
        width: 1rem;
      }
      .name:hover{
        color:#1AB2FF;
      }
      .switch {
        width: 0.8rem;
        height: 0.26rem;
        background: rgba(3, 37, 65, 1);
        border: 0px solid rgba(112, 112, 112, 1);
        border-radius: 0.2rem;
        position: absolute;
        top: 1.2rem;
        left: 1.5rem;
        cursor: pointer;
        display: flex;
        .switch-com {
          width: 0.36rem;
          height: 0.24rem;
        }
        .btnon {
          border: 1px solid #fe9999;
          background: #fe9999;
          // border-top-right-radius: 0.2rem;
          // border-bottom-right-radius: 0.2rem;
          border-top-left-radius: 0.2rem;
          border-bottom-left-radius: 0.2rem;
          position: absolute;
          // top: 0.02rem;
          // left: 0.43rem;
          top: 0.01rem;
          left: 0.01rem;
        }
        .btnoff {
          border: 1px solid rgba(13, 175, 248, 1);
          background: linear-gradient(
            360deg,
            rgba(20, 123, 252, 1) 0%,
            rgba(12, 157, 254, 1) 40%,
            rgba(3, 191, 255, 1) 100%
          );
          // border-top-left-radius: 0.2rem;
          // border-bottom-left-radius: 0.2rem;
          border-top-right-radius: 0.2rem;
          border-bottom-right-radius: 0.2rem;
          position: absolute;
          // top: 0.02rem;
          // left: 0.02rem;
          top: 0.01rem;
          left: 0.43rem;
        }
      }
      .on{
        cursor: not-allowed;
      }
    }
    .statuson {
      background: url("../../../../../assets/img/Locks/border_red.png")
        no-repeat center center;
      background-size: 100% 100%;
    }
    .statusoff {
      background: url("../../../../../assets/img/Locks/border_blue.png")
        no-repeat center center;
      background-size: 100% 100%;
    }
    .dooron {
      background: url("../../../../../assets/img/Locks/door_red.png") no-repeat
        center center;
      background-size: 100% 100%;
    }
    .dooroff {
      background: url("../../../../../assets/img/Locks/door_blue.png") no-repeat
        center center;
      background-size: 100% 100%;
    }
    .btnon {
      // background: url("../../../../../assets/img/Locks/btn_red.png") no-repeat
      //   center center;
      // background-size: 100% 100%;
    }
    .btnoff {
      // background: url("../../../../../assets/img/Locks/btn_blue.png") no-repeat
      //   center center;
      // background-size: 100% 100%;
    }
    .bgc {
      background-color: rgba(255, 255, 255, 0.2);
    }
  }
}
</style>